<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            偏函数：固定某个参数的函数
            函数柯里化：sum(a,b,c) => sum(a)(b)(c)   curry
            高级柯里化：sum(a,b,c) 即可以固定参数返回偏函数，也可以直接调用原函数   sum(a,b,c)  sum(a)(b,c) sum(a,b)(c) sum(a)(b)(c)
        */

        function say (time, word) {
            console.log(`[${ time }]: ${ this.name } speak：${ word }`);
        }
        
        var name = "window";
        
        var obj = {
            name: "obj"
        }

        // 固定say的时间

        var sayNow = say.bind(window, '12:08');
        sayNow("hello world")

        // 求任意三个数的乘积
        function mul (a, b, c) {
            console.log("mul this ", this.name);
            return a * b * c;
        }

        // 求任意两个数的2倍积
        var nul2x = mul.bind(window, 2);
        var nul3x = mul.bind(obj, 3);
        console.log(nul2x(3,2)); // mul this  window 12
        console.log(nul3x(3,3)); // mul this  obj 27
    </script>
</body>
</html>